var $$ = jQuery;
$$(function(){

/**定时消息**/
function msgservice(){
	$$.post("newuserjquery.action?usertype=three009", null, function(data){
       	var items = data.getElementsByTagName("item");
     	var result = items[0].childNodes[0].nodeValue;
     	if(result == 'success'){
			$$("#golobmsgcounthead").html(items[1].childNodes[0].nodeValue);
			$$("#golobmsgcountheadtwo").html(items[1].childNodes[0].nodeValue);
		}
   	});
}
$$(document).ready(function(){
	msgservice();
});

/*扩展*/
$$.fn.extend({

/*下拉菜单*/
downMenu:function(time,dwntg,css){
	this.mouseenter(function(){
		var menu=$$(this);
		var downMenu=menu.find(dwntg);
		dlTime=setTimeout(function(){
			menu.addClass(css);
			downMenu.slideDown(time);
		},100)
	}).mouseleave(function(){
		var menu=$$(this);
		var downMenu=menu.find(dwntg);
		clearTimeout(dlTime);
		downMenu.slideUp(time);
		menu.removeClass(css);
	})
}

})

/*弹出绑定框*/
$$.fn.extend({
addCard:function(pop){

	var mtop=$$(pop).height()/2;
	if($$(".mask").length<=0){
		$$("body").append("<div class='mask'></div>");
	}
	$$(".mask").show();
	$$(pop).show().css({"top":"50%","margin-top":-mtop,"position":"fixed"});
	$$(pop).find(".close").click(function(event){
		closePop();
		event.preventDefault();
	});
	$$(".mask").click(function(){
		closePop();
	})
	function closePop() {
		$$(pop).hide();
		$$(".mask").hide();
	}
}
})

$$.fn.extend({

/*背景移动动画*/
bgPstAnimate:function(nowX,afterX){
	$$(this).hover(function(){
		var nowLink=$$(this);
		dlTime2=setTimeout(function(){
			nowLink.animate({
				"background-position-x": afterX
			},200)
		},100)
	},function(){
		clearTimeout(dlTime2);
		$$(this).animate({
			"background-position-x": nowX
		},200)
	})
}

})


$$.fn.extend({

/*鼠标滑过显示弹出*/
showTgPop:function() {
	var nowTag=$$(this);
	var nowPop=nowTag.find("p");
	nowPop.hide();
	nowTag.hover(function(){
		tgtime=setTimeout(function(){
			nowPop.slideDown(100);
		},200)
	},function(){
		clearTimeout(tgtime);
		nowPop.slideUp(100);
	})
}

})


$$.fn.extend({

/*商品tab展示*/
divTabChange:function(tab,cont){
	var tabZone=$$(this);
	var zoneCont=tabZone.find(cont);
	var zoneTab=tabZone.find(tab);
	zoneCont.hide().eq(0).show();
	//zoneTab.find("li").eq(0).addClass("on");
	zoneTab.find("li").click(function(){
		zoneTab.find("li").removeClass();
		$$(this).addClass("on");
		var index=zoneTab.find("li").index(this);
		zoneCont.hide().eq(index).show();
	})
	zoneTab.find("a").click(function(event){
		event.preventDefault();
	})	
}
})

$$(".goodsArea").divTabChange(".gdTab",".gdWrap");
//$$(".olderWrap").divTabChange(".olderTab",".orderWrap");
//我的个人信息需要、我的订单不需要
$$(".personIn").divTabChange(".funcTab ul",".funcWrap");
$$(".photoWrap").divTabChange(".phtap",".phtCont");
//我的蜘蛛卡需要
$$(".msgWrap").divTabChange(".msgTab",".msgArea");
//我的优惠券需要
//$$("#msgNew").divTabChange(".msgCty",".msgZone");
//$$("#ymsg").divTabChange(".msgCty",".msgZone");
//$$("#emsg").divTabChange(".msgCty",".msgZone");
//$$("#msgRead").divTabChange(".msgCty",".msgZone");


/*memememememe*/
$$(".shadow_l").divTabChange(".shadow_Head",".shadow_data");
$$(".seemover_l").divTabChange(".title",".shadcont");
$$(".invitation").divTabChange(".cont",".about");


$$.fn.extend({

/*商品列表滚屏*/
scrollGoodSet:function(list,mgx,num){
	var sclwrp=$$(this);
	var sclWidth = $$(this).find(list).width();
	var sclNum = $$(this).find(list).find("li").length;
	var sclListlen = Math.ceil($$(this).find(list).find("li").length/num)-1;
	var i = 0;
	$$(this).find(list).find("ul").css("margin-left","0");
	$$(this).find(".prev").hide();
	if(sclNum > num){
		sclwrp.find(".next").show();
	}
	else{
		sclwrp.find(".next").hide();
	}
	$$(this).find(".prev").click(function(event) {
		event.preventDefault();
		if(i>0){
			i--;
			if(i==0){
				sclwrp.find(".prev").hide();
			}
			sclwrp.find(".next").show();
			turnsclList(i);
		}
	});
	$$(this).find(".next").click(function(event) {
		event.preventDefault();
		if(i<sclListlen){
			i++;
			if(i==sclListlen){
				sclwrp.find(".next").hide();
			}
			sclwrp.find(".prev").show();
			turnsclList(i);
		}
	});
	function turnsclList(index) {
		var nowLeft = -index*(sclWidth+mgx);
		sclwrp.find(list).find("ul").stop(true,false).animate({"margin-left":nowLeft},200);
	}
}

})


/*logo划屏*/
var xDist=$$(".brandList").width();
var i_logo=0;
var xTime;

$$(".brandArea .litBtn a").mouseenter(function(event){
	event.preventDefault();
	i_logo=$$(".brandArea .litBtn a").index(this);
	logoTurn(i_logo);
}).eq(0).trigger("mouseenter");

$$(".brandList").hover(function() {
	clearInterval(xTime);
	},function() {
		xTime = setInterval(function() {
		logoTurn(i_logo);
		i_logo++;
		if(i_logo == 3) {i_logo = 0;}
	},5000);
}).trigger("mouseleave");

function logoTurn(i_logo) {
	var nowLeft = -xDist*i_logo;
	$$(".brandList ul").stop(true,false).animate({"margin-left":nowLeft},300);
	$$(".brandArea .litBtn a").removeClass().eq(i_logo).addClass("on"); 
}

/*礼品首页banner划屏*/
var sWidth = $$(".imgShow").width();
var len = $$(".imgShow ul li").length;
var i_bnr = 0;
var picTimer;

for(var i=0;i<len;i++){
	$$(".bnrArea .litBtn").append("<a href='#'><img src='images/common/trans.png' width='25' height='25' alt=''></a>")
}

$$(".bnrArea .litBtn a").mouseenter(function() {
	i_bnr = $$(".bnrArea .litBtn a").index(this);
	showPics(i_bnr);
}).eq(0).trigger("mouseenter");

$$(".imgShow ul").css("width",sWidth * (len));

$$(".imgShow").hover(function() {
	clearInterval(picTimer);
	},function() {
		picTimer = setInterval(function() {
		showPics(i_bnr);
		i_bnr++;
		if(i_bnr == len) {i_bnr = 0;}
	},4000);
}).trigger("mouseleave");

function showPics(index) {
	var nowLeft = -index*sWidth;
	$$(".imgShow ul").stop(true,false).animate({"margin-left":nowLeft},300);
	$$(".bnrArea .litBtn a").removeClass("on").eq(index).addClass("on");
}


/*推荐商品轮换*/
var gdWidth = $$(".btgdPart").width();
var scllen = Math.ceil($$(".btgdPart .clmnList2 li").length/5);
var gd_bnr = 0;
var gdTimer;
var dist=45;

for(var i=0;i<scllen;i++){
	$$(".dotNav").append("<li><img width='24' height='24' src='images/common/trans.png' alt=''></li>")
}

$$(".dotNav li").mouseenter(function() {
	gd_bnr = $$(".dotNav li").index(this);
	showGoods(gd_bnr);
}).eq(0).trigger("mouseenter");

$$(".btgdPart .clmnList2").css("width",gdWidth * (scllen));

$$(".btgdPart").hover(function() {
	clearInterval(gdTimer);
	},function() {
		gdTimer = setInterval(function() {
		showGoods(gd_bnr);
		gd_bnr++;
		if(gd_bnr == scllen) {gd_bnr = 0;}
	},4000);
}).trigger("mouseleave");

function showGoods(index) {
	var nowLeft;
	if(index==0){
		nowLeft=0;
	}
	else{
		nowLeft = -index*gdWidth+dist*index;
	}
	$$(".btgdPart .clmnList2").stop(true,false).animate({"margin-left":nowLeft},300);
	$$(".dotNav li").removeClass("on").eq(index).addClass("on");
}

/*最近浏览商品轮换*/
var hstgdHeight = $$(".sdlistWrp").height();
var hstscllen = Math.ceil($$(".sdlistWrp .clmnList1 li").length/3);
var hstgd_bnr = 0;
var hstgdTimer;

for(var i=0;i<hstscllen;i++){
	$$(".dotNav2").append("<li><img width='13' height='13' src='images/common/trans.png' alt=''></li>")
}

$$(".dotNav2 li").mouseenter(function() {
	hstgd_bnr = $$(".dotNav2 li").index(this);
	hstshowGoods(hstgd_bnr);
}).eq(0).trigger("mouseenter");

$$(".sdlistWrp .clmnList1").css("height",hstgdHeight * (hstscllen));

$$(".sdlistWrp").hover(function() {
	clearInterval(hstgdTimer);
	},function() {
		hstgdTimer = setInterval(function() {
		hstshowGoods(hstgd_bnr);
		hstgd_bnr++;
		if(hstgd_bnr == hstscllen) {hstgd_bnr = 0;}
	},4000);
}).trigger("mouseleave");

function hstshowGoods(index) {
	var nowTop;
	if(index==0){
		nowTop=0;
	}
	else{
		nowTop = -index*hstgdHeight;
	}
	$$(".sdlistWrp .clmnList1").stop(true,false).animate({"margin-top":nowTop},300);
	$$(".dotNav2 li").removeClass("on").eq(index).addClass("on");
}


/*图片信息弹出*/
$$(".showhold").find(".hold").hide();
var sldTime;
$$(".showhold").hover(function(){
	var ngood=$$(this);
	sldTime=setTimeout(function(){
		ngood.find(".hold").slideDown(400)
	},100);
},function(){
	clearTimeout(sldTime);
	$$(this).find(".hold").slideUp(400);
})

/*栏目切换*/
$$(".fesvTab li").mouseenter(function(){
	$$(".fesvTab li").removeClass();
	$$(this).addClass("on");
	var index=$$(".fesvTab li").index(this);
	$$(".fesvCont").css("display","none").eq(index).fadeIn(500);
})

/*城市切换*/
var nowcity=$$("#city .chs").text();
var cityList=$$("#city .ctype a");
for(var i=0;i<cityList.length;i++){
	if(cityList.eq(i).text()==nowcity){
		$$("#city .ctype a").eq(i).addClass("now");
		break;
	}
}
$$("#city .ctype a").click(function(event){
	event.preventDefault();
	var mycity=$$(this).text();
	$$("#city .chs").text(mycity);
	$$("#city .ctype a").removeClass();
	$$(this).addClass("curr");
})

/*logo鼠标滑过效果*/
var nowh2logo;
$$(".logo").hover(function(){
	nowh2logo=$$(this).find("h2 img").attr("src");
	$$(this).find("h2 img").attr("src","/images/common/logo_slogen.gif");
},function(){
	$$(this).find("h2 img").attr("src",nowh2logo);
})


/*自适应屏幕宽度*/
function winResize() {
	var winWidth=$$(window).width();
	
	var bnrlen = $$(".showArea .gdShow li").length;
	if(winWidth<1200){
		dist=32;
		$$("body").addClass("w980");
		$$("#browse").scrollGoodSet(".footList",0,4);
		$$("#gpGdList").scrollGoodSet(".gpGoodWrp",1,3);
		
		setTimeout(function(){
			$$("#recommend").scrollGoodSet(".footList",0,4);
		},10000);

		
		
		$$("#collect").scrollGoodSet(".clltList",48,3);
		$$("#myfilm").scrollGoodSet(".itemList",0,3);

		/*礼品众筹banner划屏*/
		function showbnrs2(index){
			var btnLeft = 116*index;
			var nowLeft = -index*574;
			$$(".showArea .gdShow ul").stop().animate({"margin-left":nowLeft},300);
			$$(".showArea .showon").stop().animate({
				left:btnLeft
			},300)
		};

		$$(".showArea .gdShow ul").css("width",574 * (bnrlen));
		$$(".showArea .showon").css("top","0");
		var now_bnr1 = 0;
		$$(".gdNav li").mouseenter(function() {

			now_bnr1 = $$(".gdNav li").index(this);
			showbnrs2(now_bnr1);
		}).eq(0).trigger("mouseenter");
		
	}
	else{
		dist=45;
		$$("body").removeClass();
		$$("#browse").scrollGoodSet(".footList",9,5);
		$$("#gpGdList").scrollGoodSet(".gpGoodWrp",1,4);
		setTimeout(function(){
			$$("#recommend").scrollGoodSet(".footList",9,5);
		},10000);
		$$("#collect").scrollGoodSet(".clltList",9,3);
		$$("#myfilm").scrollGoodSet(".itemList",0,4);

		/*礼品众筹banner划屏*/		
		function showbnrs1(index) {
			var	btnTop = 123*index;
			var	nowLeft = -index*608;
			$$(".showArea .gdShow ul").stop().animate({"margin-left":nowLeft},300);
			$$(".showArea .showon").stop().animate({
				top:btnTop
			},300);
		};

		$$(".showArea .gdShow ul").css("width",608 * (bnrlen));
		$$(".showArea .showon").css("left","0");
		var now_bnr2 = 0;
		$$(".gdNav li").mouseenter(function() {
			now_bnr2 = $$(".gdNav li").index(this);
			showbnrs1(now_bnr2);
		}).eq(0).trigger("mouseenter");

	}
	xDist=$$(".brandList").width();
	logoTurn(i_logo);

	sWidth = $$(".imgShow").width();
	$$(".imgShow ul").css("width",sWidth * (len));
	showPics(i_bnr);

	gdWidth = $$(".btgdPart").width();
	gd_bnr=0;
	showGoods(gd_bnr);	
}



/*调用*/
winResize();
$$(window).resize(function(){
	winResize();
})

//$$(".subMenu").downMenu(100,"div","");
$$(".myAcct").downMenu(50,"ul","open");
$$(".phone").downMenu(50,"ul","open");
$$(".trolley").downMenu(50,".trlcont","open");
$$(".service").downMenu(50,"ul","open");
$$(".acctSet").downMenu(20,"ul","open");
$$(".typeItem").downMenu(100,"ul","on");
$$("#city").downMenu(100,".citychs","on");
$$("#storeSelector").downMenu(100,".stCity","");
$$(".tipoff").downMenu(100,"a","hover");
$$(".wuliu").downMenu(100,".prompt","");
$$(".receiver").downMenu(100,".getmanPp","");
$$("#preview .specList").scrollGoodSet(".specItem",0,4);
/*鼠标停留弹出层*/
$$("#mail").showTgPop();
$$("#phon").showTgPop();
$("#zflx").divTabChange(".funcTab001",".funcWrap001");


/*显示弹出层*/
$$(".showpop a").click(function(event){
	if($$(".mask").length<=0){
		$$("body").append("<div class='mask'></div>");
	}
	var now_i=$$(".showpop a").index(this);
	event.preventDefault();
	var nowTab=$$(this).text();
	$$(".mask").hide();
	var popDiv=$$(".photoPop");
	if(popDiv.css("display")=="none"){
		popDiv.show();
		$$(".mask").show();
	};
	$$(".mask").click(function(){
		closePop();
	});
	$$(".photoPop .close").click(function(event){
		closePop();
		event.preventDefault();
	});
	showOpt(now_i);
	function closePop() {
		popDiv.hide();
		$$(".mask").hide();
	}
	function showOpt(i) {
		$$(".phtap li").removeClass().eq(i).addClass("on");
		$$(".phtCont").hide().eq(i).show();
	}
})

/*二维码随屏滚动*/
$$(window).scroll(function(){
	var dcmscl_height=$$(document).scrollTop();
	var page_height=$$(document).height();
	if(dcmscl_height>550){
		if(dcmscl_height<page_height-1388){
			$$(".dmsCode").css("top",dcmscl_height);
		}
		else{
			$$(".dmsCode").css("top",page_height-1388);
		}
	}	
	else{
		$$(".dmsCode").css("top","605px");
	}
})
/*关闭二维码*/
$$(".dmsClose").click(function(){
	$$(".dmsCode").hide();
})



/*头像划过效果*/
$$(".portrait a").hide();
$$(".portrait").hover(function(){
	$$(this).find("a").show();
},function(){
	$$(this).find("a").hide();
})

/*左侧菜单开启&关闭*/
$$(".menuPart h4").click(function(){
	var mainmenu=$$(this);
	var submenu=$$(this).siblings("ul");
	var substate=submenu.css("display");
	if(substate=="block"){
		submenu.slideUp(200);
		mainmenu.addClass("close");
	}
	else if(substate=="none"){
		submenu.slideDown(200);
		mainmenu.removeClass();
	}
})

/*图片划过效果*/
$$(".phtCont table td").not($$(".bdnone")).hover(function(){
	$$(this).css("border","1px solid #ff4747");
},function(){
	$$(this).css("border","1px solid #e5e5e5");
})

/*地址栏划过效果*/
$$(".addrList .addtool a").hide();
$$(".addrList .close").hide();
$$(".addrList li").hover(function(){
	$$(this).find(".addtool a").show();
	$$(this).find(".close").show();
	$$(this).find(".addef").hide();
},
	function(){
	$$(this).find(".addtool a").hide();
	$$(this).find(".close").hide();
	$$(this).find(".addef").show();
})

/**/

})